package com.billing.persistance.entities;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.NumberFormat;
import org.springframework.format.annotation.NumberFormat.Style;

@Entity
@Table(name = "BILLING_ENTRY")
public class BillingEntry implements IBusinessEntity {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@NotNull
	@Column(name = "DESCRIPTION")
	private String description;

	@NotNull
	@NumberFormat(style=Style.NUMBER)
	@Column(name = "AMOUNT")
	private Double amount;

	@NotNull
	@Column(name = "EXECUTION_DATE")
	private Date date;

	@ManyToOne
	@JoinColumn(name = "OWNER")
	private TechUser owner;

	@ManyToOne
	@JoinColumn(name = "PAYEE")
	private BillOwner payee;

	@ManyToOne
	@JoinColumn(name = "PAYER")
	private BillOwner payer;

	@ManyToOne
	@JoinColumn(name = "INVOICE", nullable = true)
	private Invoice invoice;

	@ManyToOne
	@JoinColumn(name = "CONCEPT", nullable = true)
	private BillingEntryConcept concept;

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("BillingEntry [" + id + "]");
		return sb.toString();
	}

	// //////////////////////////////////////////////////////////////
	// Getters and setters
	// //////////////////////////////////////////////////////////////

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@DateTimeFormat(pattern="dd/MM/yyyy")
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public TechUser getBillOwner() {
		return owner;
	}

	public void setBillOwner(TechUser billOwner) {
		this.owner = billOwner;
	}

	public Invoice getInvoice() {
		return invoice;
	}

	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}

	public BillingEntryConcept getBillingEntryConcept() {
		return getConcept();
	}

	public void setBillingEntryConcept(BillingEntryConcept concept) {
		this.setConcept(concept);
	}

	public BillOwner getPayer() {
		return payer;
	}

	public void setPayer(BillOwner payer) {
		this.payer = payer;
	}

	public BillOwner getPayee() {
		return payee;
	}

	public void setPayee(BillOwner payee) {
		this.payee = payee;
	}

	public BillingEntryConcept getConcept() {
		return concept;
	}

	public void setConcept(BillingEntryConcept concept) {
		this.concept = concept;
	}

}